﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WarOfDev.Core.ExceptionHandling.ExceptionDetails;
using System.Runtime.Serialization;

namespace WarOfDev.Core.ExceptionHandling.Exceptions
{
    [Serializable]
    public class WofException<T> : Exception where T : Detail
    {
        private T detail;


        public WofException()
            : base()
        {

        }

        public WofException(string message)
            : base(message)
        {

        }

        public WofException(string message, Exception err)
            : base(message, err)
        {

        }

        public WofException(string message, Exception err, T detail)
            : base(message, err)
        {
            this.detail = detail;
        }


        protected WofException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            info.AddValue("Detail", this.detail);
        }


        public T Detail
        {
            get { return this.detail; }
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);

            this.detail = (T)info.GetValue("Detail", typeof(T));
        }
    }
}
